<!-- 系统信息详情页面 -->
<template>
	<view class="content">
		<view class="topbg">
			<view class="nav_title">
				<image src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/left.png" @click="back"></image>
				<view class="">系统消息</view>
			</view>
			<view class="content_detail">
				<view class="title">
					<text>{{info.title}}</text>
				</view>
				<view class="detailInfo">
					<rich-text :nodes="info.richText"></rich-text>
					<view class="time">
						<view>发送时间：{{info.createTime}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		messageDetails,
		setMessageRead
	} from '@/apis/apis.js'
	export default {
		data() {
			return {
				id: "",
				info: {},
				flag: -1,
				timer: null
			}
		},
		onLoad(options) {
			// console.log(options)
			this.id = options.id ? options.id : ""
			this.flag = options.flag ? options.flag : -1
		},
		onShow() {
			this.init()
			if (this.flag == -1) {
				this.setDoneApi()
			}
		},
		methods: {
			init() {
				messageDetails(this.id).then(res => {
					console.log(res)
					res.data.richText = res.data.richText.replace(/<img /, '<img style="max-width:100%;"')
					res.data.richText = res.data.richText.replace(/<p>/, '<p style="font-size:35rpx">')
					this.info = res.data
				})
			},
			// 设置为已读
			setDoneApi() {
				setMessageRead({
					messageIds: this.id
				}).then(res => {
					// console.log(res)
				})
			},
			back() {
				//判定是否已读
				let isRead = this.flag == 0 ? true : false
				this.timer = setTimeout(() => {
					uni.navigateBack()
				}, 500)
				const pages = getCurrentPages()
				const prevPage = pages[pages.length - 2]
				prevPage.$vm.sendValue(isRead)
			}
		},
		onUnload() {
			//销毁定时器
			if (this.timer) {
				clearTimeout(this.timer)
				this.timer = null
			}
		}

	}
</script>

<style scoped lang="scss">
	.content {
		width: 100%;
		height: 100vh;
		background-color: #F4F6F8;

		.topbg {
			width: 100%;
			height: 256rpx;
			background: #194FC9;
			border-radius: 0px 0px 15px 15px;

			.nav_title {
				color: #fff;
				font-size: 32rpx;
				display: flex;
				align-items: center;
				padding: 70rpx 0 0 32rpx;

				&>image {
					width: 16rpx;
					height: 28rpx;
					margin-right: 268rpx;
				}
			}

			.content_detail {
				// width: 690rpx;
				border-radius: 20rpx;
				background-color: #fff;
				position: absolute;
				top: 140rpx;
				left: 30rpx;
				right: 30rpx;

				max-height: 81vh;
				overflow: hidden;
				overflow-y: visible;

				.title {
					padding: 30rpx;
					border-bottom: 2rpx solid #E9E9E9;
					color: #1A1A1A;
					font-size: 30rpx;
					font-weight: bold;
				}

				.detailInfo {
					padding: 30rpx;
					color: #B7B7B7;
					font-size: 26rpx;


					&>text {
						color: #999999;
						font-size: 28rpx;
						line-height: 44rpx;
					}

					.time {
						height: 40rpx;
						display: flex;
						justify-content: flex-end;
						align-items: center;

						&>text {
							margin-right: -36rpx;
						}
					}
				}
			}
		}
	}
</style>
